package cn.wolfcode.mp.web.controller;


import cn.wolfcode.mp.qo.JsonResult;
import cn.wolfcode.mp.service.IPermissionService;
import cn.wolfcode.mp.util.RequiredPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("permissions")
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

    @GetMapping("/list")
    @RequiredPermission(name = "权限页面",expression = "permission:list")
    public JsonResult list(){
        return new JsonResult(permissionService.list());
    }

    @DeleteMapping("/delete")
    @RequiredPermission(name = "权限删除",expression = "permission:delete")
    public JsonResult delete(Long id){
        permissionService.removeById(id);
        return new JsonResult();
    }

    @GetMapping("/load")
    @RequiredPermission(name = "权限加载",expression = "permission:load")
    public JsonResult load(){
        permissionService.load();
        return new JsonResult(true,"权限加载成功");
    }

}
